package com.lysj.admin.gateway.filter;

import com.lysj.admin.gateway.constants.GatewayConstants;
import com.lysj.admin.gateway.constants.JwtUtils;
import com.lysj.admin.utils.web.ParamUtil;
import com.netflix.zuul.ZuulFilter;
import com.netflix.zuul.context.RequestContext;
import lombok.Data;
import org.springframework.beans.factory.annotation.Value;

import javax.servlet.http.HttpServletRequest;

/**
 * @author Created by zk on 2019-01-16 15:41
 * @description
 */
@Data
public abstract class MyAbstractPreZuulFilter extends ZuulFilter {
    @Value("${secret.header}")
    private String header;
    private String IssName;
    private String token;

    @Override
    public boolean shouldFilter() {
        HttpServletRequest request = RequestContext.getCurrentContext().getRequest();
        boolean isSuccess = true;
        String isSuccessStr = request.getAttribute(GatewayConstants.IS_SUCCESS_NAME).toString();
        if(!ParamUtil.isBlank(isSuccessStr)){
            isSuccess = Boolean.parseBoolean(isSuccessStr);
        }
        if(isSuccess){
            token = request.getHeader(header);
            IssName = request.getAttribute(GatewayConstants.JWT_ISSUER).toString();
        }
        return isSuccess;
    }
}
